import { _decorator, Component, Node, SpriteFrame } from 'cc';
import { _platform, _player, _tip } from '../Main';
const { ccclass, property } = _decorator;

@ccclass('BaseItem')
export abstract class BaseItem {
    
    innerName: string = BaseItem.name

    abstract showName: string

    abstract shortDesc: string

    abstract fullDesc: string

    icon: SpriteFrame = null

    abstract storeAt: {}

    cost: number = 0

    constructor(icon: SpriteFrame = null) {
        this.icon = icon
    }

    getIdName(): string {
        return this.innerName + '-' + this.showName
    }

    getLimitName(): string {
        return 'limit-' + this.showName
    }

    video(amount: number = 1, then?: () => void) {
        _platform.platform.showVideo(() => {
            this.get(amount, then)
        })
    }

    get(amount: number = 1, then?: () => void) {
        _player.changeNumData(this.getIdName(), this.storeAt, amount, 'add', true, () => {
            _tip.tip('获得 ' + this.showName + ' ×' + amount)
            if (then) {
                then()
            }
        })
    }
}


